package br.com.dev.tcc.view.sinistro;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import br.com.dev.tcc.R;
import br.com.dev.tcc.adapter.GridSinistroAdapter;
import br.com.dev.tcc.bean.sinistro.BaseViewSinistroItem;
import br.com.dev.tcc.model.SinistroTipoModel;
import br.com.dev.tcc.singleton.SinistroSingleton;
import br.com.dev.tcc.view.DefaultSupportActionBarActivity;

public class SelecionaTipoSinistroActivity extends
		DefaultSupportActionBarActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.grid_base);
		setActionBar(R.string.sinistro, R.string.criar_sinistro,
				R.drawable.sinistro);

		SinistroTipoModel model = new SinistroTipoModel(this);
		final List<BaseViewSinistroItem> gridItens = model.getGridItens(SinistroSingleton.getInstance().getApolice().getPlano());

		GridView grid = (GridView) findViewById(R.id.grid);
		GridSinistroAdapter adapter = new GridSinistroAdapter(this, gridItens);
		adapter.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> a, View v, int position,
					long id) {

				SinistroSingleton.getInstance().setTipo(
						gridItens.get(position).getTipo());
				startActivity(new Intent(SelecionaTipoSinistroActivity.this,
						AbrirSinistroActivity.class));
				finish();
			}
		});
		grid.setAdapter(adapter);
	}
}
